package com.kh.samr.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;

/**
 * 红黑名单查询参数
 *
 * @author Harry
 * @date 2021/4/12
 */
@Table(name = "dishonesty_param")
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DishonestyParam implements Serializable {

	private static final long serialVersionUID = -7327146936640351656L;

	/**
	 * 统一社会信用代码
	 */
	@Id
	@Column(name = "uniform_social_credit_code", length = 18)
	@NotBlank(message = "统一社会信用代码不能为空")
	private String uniformSocialCreditCode;

	/**
	 * 企业名称
	 */
	@Column(name = "enterprise_name", nullable = false)
	@NotBlank(message = "企业名称不能为空")
	private String enterpriseName;

	/**
	 * 创建时间
	 */
	@ApiModelProperty(value = "创建时间", readOnly = true, example = "yyyy-MM-dd HH:mm:ss")
	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private Date creatTime;

	/**
	 * 最近修改时间
	 */
	@ApiModelProperty(value = "最近修改时间", readOnly = true, example = "yyyy-MM-dd HH:mm:ss")
	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Temporal(TemporalType.TIMESTAMP)
	private Date updateTime;

	@PrePersist
	private void entityBeforeInsert() {
		setCreatTime(new Date());
		setUpdateTime(new Date());
	}

	@PreUpdate
	private void entityBeforeModify() {
		setUpdateTime(new Date());
	}
}
